home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / amigae.jan.archive / 000022_nkraft_Sun, 9 Jan 94 22:48:56 PST.msg < prev    next >
Text File  |  1994-02-17  |  10KB  |  243 lines

  1. Received: by bkhouse.cts.com (V1.16/Amiga)
  2.     id AA00000; Sun, 9 Jan 94 22:48:56 PST
  3. Date: Sun, 9 Jan 94 22:48:56 PST
  4. Message-Id: <9401100648.AA01js3@bkhouse.cts.com>
  5. X-Mailer: //\\miga Electronic Mail (AmiElm 2.253)
  6. Organization: Argus Computing, San Diego, CA
  7. Reply-To: nkraft@bkhouse.cts.com
  8. From: nkraft@bkhouse.cts.com (Norman R. Kraft)
  9. To: 
  10. Subject: ADMIN: Lost Mail
  11.  
  12. Due to some problems with my feed system, several (four,
  13. I think) incoming mailings destined for the amigae list
  14. were lost before making it to the list. There were really
  15. very few of these, so wait around a day or two and if
  16. you don't see your mail on the list, try resending it.
  17.  
  18. Sorry for the inconvenience.
  19.  
  20. Norm.
  21.  
  22.  
  23. ----------------------------------------------------------------------------
  24. Norman Kraft                            INET  : nkraft@ucsd.edu (work)
  25. Peptide-T Clinical Trial                or try: nkraft@bkhouse.cts.com (home)
  26. HIV Neurobehavioral Research Center     UUCP  : ucsd!nkraft
  27. Dept of Psychiatry, School of Medicine  
  28. University of California, San Diego          Usual disclaimers...
  29. ----------------------------------------------------------------------------
  30. From crash!comlab.oxford.ac.uk!ecs.oxford.ac.uk!m88jrh Mon, 10 Jan 94 02:11:04 PST
  31. Received: by bkhouse.cts.com (V1.16/Amiga)
  32.     id AA00000; Mon, 10 Jan 94 02:11:04 PST
  33. Received: from sun2.nsfnet-relay.ac.uk by crash.cts.com with smtp
  34.     (Smail3.1.28.1 #18) id m0pJIUh-0000L5C; Mon, 10 Jan 94 01:01 PST
  35. Received: from ecs.oxford.ac.uk (ecs.ecs) by comlab.oxford.ac.uk id AA10716;
  36.           Mon, 10 Jan 94 09:00:06 GMT
  37. Received: from ecs.ox.ac.uk (booth6.ecs) by ecs.oxford.ac.uk (4.1/ecs.1) 
  38.           id AA24506; Mon, 10 Jan 94 09:02:36 GMT
  39. Received: by ecs.ox.ac.uk (4.1/ecs2.0) id AA00275; Mon, 10 Jan 94 09:01:13 GMT
  40. Via: uk.ac.oxford.comlab; Mon, 10 Jan 1994 09:00:17 +0000
  41. Date: Mon, 10 Jan 94 09:01:13 GMT
  42. Message-Id: <9401100901.AA00275@booth6.ecs.ox.ac.uk>
  43. From: m88jrh@ecs.oxford.ac.uk
  44. To: amigae@bkhouse.cts.com
  45. Subject: SetFunction and calling E code
  46.  
  47.  
  48. Some time ago I was trying to get SetFunction() to work from E.  I tried all
  49. kinds of things (and not very many of them were sensible).  Recently I asked
  50. Wouter if he could give me an example of how to use CreateNewProc() from E
  51. and he came up with a lovely little example (albeit using AddTask()).  Then
  52. everything fell into place and I realised what I'd been doing wrong.  The
  53. following example program shows, I think, how you should do it.
  54.  
  55. So, to the vital clue:  to use an E procedure from another task you need
  56. some way of setting register A4 to the correct value.  The simplest way is
  57. to use self-modifying code (yuk!), as in the example below where "store" is
  58. used.  The procedure (or labelled code) which is run from a different task
  59. must reinstate A4 to the stored value before it can use any E variables.  Of
  60. course, you can save things on the stack before changing A4 if you need to.
  61.  
  62. Now the example: this behaves a bit like SnoopDos, monitoring calls to
  63. OpenLibrary() (in exec.library).  It uses the SetFunction() call to run
  64. a piece of E code instead of the normal OpenLibrary() code.  There are
  65. several points worth mentioning:
  66.  
  67. 1) Self-modifying code in two places: "store" and "patch".  This means this
  68.    program might not work properly on machines with large instruction caches
  69.    (it works OK on my A1200, though).  I'd like to know if someone can get
  70.    rid of the "patch" kludge --- the "store" stuff is respectable in
  71.    comparison.  BTW, the "JMP (A0)" kind of thing didn't work...
  72. 2) Use of a message port to enable some visible output.  Because I'm lazy I
  73.    used the Release 2 (and above) CreateMsgPort()/DeleteMsgPort() calls.
  74.    (Will E v3.0 have an amiga.m module like C's amiga.lib?)
  75.    This is a *very* important point: because our patched routine might not
  76.    be run by a process we cannot use any dos.library calls.  However, we
  77.    can send a message to the process that did the patch and tell it what to
  78.    print!
  79. 3) Moving on to the patched routine (labelled "newf"), the first thing that
  80.    is done is preserving all the registers.  We don't want to muck up the
  81.    arguments that were sent to the OpenLibrary() call.
  82. 4) Luckily, the call to sendmsg() from the patched routine seems to
  83.    preserve A1, which is what we are interested in. (Wouter, what registers
  84.    can we rely on being preserved?)
  85. 5) sendmsg() works out the name of the task that is running it and sends
  86.    this name and the name of the library in a message.
  87. 6) Back in main(), the patching process is waiting for a CTRL-C from the
  88.    user or a message on its (private) port.  Any messages received are
  89.    processed and printed nicely (!).
  90. 7) The first Disable() call is necessary. The second is probably not (call
  91.    me paranoid if you will).  I think the PutMsg() does not need wrapping
  92.    in Disable()/Enable() (or Forbid()/Permit()) because we know the port
  93.    isn't going away...
  94. 8) The New() call from the patched routine seems to work.  And the memory
  95.    seems to be added to the patching routine's memory list and freed when
  96.    it terminates.  All the same I threw in some Dispose[Link]()'s (in
  97.    printmsgs()) to allow some re-use of memory whilst it's running).
  98. 9) Using SetFunction() can never be 100% reliable so don't do it ;-)
  99.    What this means is: don't expect something like this to work if you have
  100.    another program messing with the library...
  101.  
  102. Well, I hope this is correct and (or?) helpful...
  103.  
  104.  
  105. ----------------------  CUT HERE ------------------------------------------
  106. /* setf.e -- a SnoopDos-like program to monitor calls to OpenLibrary() */
  107.  
  108. OPT OSVERSION=37
  109.  
  110. MODULE 'dos/dos', 'exec/ports', 'exec/tasks', 'exec/nodes'
  111.  
  112. CONST OFFSET=$fdd8  /* execbase offset of OpenLibrary() */
  113.  
  114. /* "mymsg" must begin with the standard message object "mn", followed by
  115.    any kind of data (in this case, two pointers [to strings]).
  116. */
  117. OBJECT mymsg
  118.   msg:mn
  119.   s, t
  120. ENDOBJECT
  121.  
  122. /* "port" will be used from the patched routine, too, so it's global */
  123. DEF port:PTR TO mp
  124.  
  125. /* You can change the library function to be patched by changing OFFSET
  126.    and the "execbase" in the *two* calls to SetFunction().  If you want to
  127.    patch a library other than dos, exec, graphics and intuition you need
  128.    to OpenLibrary() it first.
  129.    (Note: some [old?] libraries cannot be patched in this way.  Also, some
  130.    functions in some libraries can't be patched like this either!  Even the
  131.    RKRM's aren't too clear about this...)
  132. */
  133. PROC main()
  134.   DEF ps, us, addr, loop, sig, oldf
  135.   IF port:=CreateMsgPort()
  136.     Disable()     /* Don't let anyone mess things up... */
  137.     IF oldf:=SetFunction(execbase, OFFSET, {newf})
  138.       addr:={patch}+2
  139.       ^addr:=oldf
  140.       Enable()    /* Now we can let everyone else back in */
  141.       LEA store(PC), A0
  142.       MOVE.L A4, (A0)    /* Store the A4 register... */
  143.       ps:=Shl(1,port.sigbit)   /* Set up port and user signal bits */
  144.       us:=SIGBREAKF_CTRL_C
  145.       loop:=TRUE
  146.       WHILE loop
  147.         sig:=Wait(ps OR us)
  148.         IF sig AND ps
  149.           printmsgs()
  150.         ENDIF
  151.         IF sig AND us
  152.           loop:=FALSE
  153.         ENDIF
  154.       ENDWHILE
  155.       Disable()   /* Paranoid... */
  156.       SetFunction(execbase, OFFSET, oldf)
  157.     ENDIF
  158.     Enable()
  159.     printmsgs()   /* Make sure the port is empty */
  160.     DeleteMsgPort(port)
  161.   ENDIF
  162. ENDPROC
  163.  
  164. /* Nicely (?) print the messages out... */
  165. PROC printmsgs()
  166.   DEF msg:PTR TO mymsg
  167.   WHILE msg:=GetMsg(port)
  168.     WriteF('Task \l\s[25] wants \r\s[20]\n', msg.t, msg.s)
  169.     /* Not really necessary to ReplyMsg() in this example */
  170.     ReplyMsg(msg)
  171.     DisposeLink(msg.t)
  172.     DisposeLink(msg.s)
  173.     Dispose(msg)
  174.   ENDWHILE
  175. ENDPROC
  176.  
  177. /* Send a message to the patching process */
  178. PROC sendmsg()
  179.   DEF m:PTR TO mymsg, s, tsk:tc, l:ln
  180.   MOVE.L A1, s
  181.   m:=New(SIZEOF mymsg) /* Allocate a new message */
  182.   IF s
  183.     m.s:=String(StrLen(s))
  184.     StrCopy(m.s,s,ALL)
  185.   ELSE
  186.     m.s:='*unnamed library*'
  187.   ENDIF
  188.   tsk:=FindTask(NIL)   /* Find out who we are */
  189.   m.t:=NIL
  190.   IF tsk
  191.     l:=tsk.ln
  192.     IF l AND l.name
  193.       m.t:=String(StrLen(l.name))
  194.       StrCopy(m.t, l.name, ALL)
  195.     ENDIF
  196.   ENDIF
  197.   IF m.t=NIL
  198.     m.t:='*unnamed task*'
  199.   ENDIF
  200.   PutMsg(port, m)
  201. ENDPROC
  202.  
  203. /* Place to store A4 register */
  204. store:  LONG 0
  205.  
  206. /* The new routine which will replace the original library function */
  207. newf:
  208.   MOVEM.L D0-D7/A0-A6, -(A7)
  209.   LEA store(PC), A0
  210.   MOVE.L (A0), A4 /* Reinstate the A4 register so we can use E code */
  211.   sendmsg()
  212.   MOVEM.L (A7)+, D0-D7/A0-A6
  213. patch:
  214.   JMP $0
  215. /* Yukky patch to the JMP code... */
  216.  
  217. ----------------------  CUT HERE ------------------------------------------
  218.  
  219. ---
  220.    _____  _
  221.      /   / |    /  /
  222.     /   /__/   /__/      Jason R. Hulance
  223.    /   /\     /  /   <m88jrh@uk.ac.oxford.ecs>
  224. |_/ . /  \ . /  / .
  225. From crash!aston.ac.uk!sun.aston.ac.uk!nichowlw Mon, 10 Jan 94 03:41:46 PST
  226. Received: by bkhouse.cts.com (V1.16/Amiga)
  227.     id AA00000; Mon, 10 Jan 94 03:41:46 PST
  228. Received: from sun2.nsfnet-relay.ac.uk by crash.cts.com with smtp
  229.     (Smail3.1.28.1 #18) id m0pJKyO-0000VQC; Mon, 10 Jan 94 03:39 PST
  230. Received: from denmark by email.aston.ac.uk with SMTP (PP) 
  231.           id <22885-0@email.aston.ac.uk>; Mon, 10 Jan 1994 11:37:24 +0000
  232. Via: uk.ac.aston; Mon, 10 Jan 1994 11:38:52 +0000
  233. Date: Mon, 10 Jan 94 11:38:16 GMT
  234. Message-Id: <16257.9401101138@sun.aston.ac.uk>
  235. X-Sun-Charset: US-ASCII
  236. content-length: 61
  237. From: nichowlw <nichowlw@sun.aston.ac.uk>
  238. To: AmigaE@bkhouse.cts.com
  239. Subject: Unsubscribe
  240.  
  241. Please Unsubscribe me from the AmigaE mailing list.
  242.  
  243. Thanks